﻿using System;
using System.Collections.Generic;
using System.Windows.Media;
using DBAccessLibrary.Model;
using System.Data;
using System.Collections.ObjectModel;
using DataAccess;

namespace DBAccessLibrary.Interface
{
    /// <summary>
    /// 数据操作接口
    /// </summary>
    public interface IOperations
    {
        /// <summary>
        /// 构建实体
        /// </summary>
        /// <param name="list"></param>
        /// <param name="log"></param>
        /// <param name="begioninvoke"></param>
        /// <returns></returns>
        bool CreateDBEntity(ObservableCollection<DataBaseEntity> list, Action<string,Color> log, Action<Action> begioninvoke);
        /// <summary>
        /// 回滚事务
        /// </summary>
        /// <param name="connect"></param>
        void RollbackTransaction(ConnectionModel connect);
        /// <summary>
        /// 提交事务
        /// </summary>
        /// <param name="connect"></param>
        void CommitTransaction(ConnectionModel connect);
        /// <summary>
        /// 连接数据库
        /// </summary>
        /// <param name="connect"></param>
        /// <param name="exec"></param>
        /// <param name="transaction"></param>
        void ConnectDB(ConnectionModel connect, Action<ConnectionModel, IDataAccess> exec, TransactionType transaction = TransactionType.NoTransaction);
        void ConnectDB(ConnectionModel connect);
        /// <summary>
        /// 执行SQL 命令
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="connect"></param>
        /// <param name="paramlist"></param>
        /// <param name="transaction"></param>
        void ExecSql(string sql, ConnectionModel connect = null, List<DBParam> paramlist = null, TransactionType transaction = TransactionType.NoTransaction);
        object ExecScalar(string sql, ConnectionModel connect = null, List<DBParam> paramlist = null, TransactionType transaction = TransactionType.NoTransaction);
        int ExecNonQuery(string sql, ConnectionModel connect = null, List<DBParam> paramlist = null, TransactionType transaction = TransactionType.NoTransaction);
        DataSet ExecSqlToDS(string sql, ConnectionModel connect = null, List<DBParam> paramlist = null, TransactionType transaction = TransactionType.NoTransaction);
        DataSet ExecProc(string procName, List<DBParam> paramlist, out Dictionary<string, object> outdic, ConnectionModel connect = null, TransactionType transaction = TransactionType.NoTransaction);
        /// <summary>
        /// 是否连接成功
        /// </summary>
        /// <param name="connect"></param>
        /// <returns></returns>
        string IsConnectDB(ConnectionModel connect);

        /// <summary>
        /// 返回表和列信息
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="log"> </param>
        /// <returns></returns>
        DbEntityCache GetDbInfos(ConnectionModel connection, Action<string, Color> log);
        /// <summary>
        /// 保存描述信息
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="fieldName"></param>
        /// <param name="chtablename"></param>
        /// <param name="chfieldname"></param>
        /// <param name="fieldType"></param>
        /// <param name="fieldLength"></param>
        /// <param name="isPrimary"></param>
        void SaveDescription(TableEntity table, FieldEntity field, string newChStr, bool isnewTable, TransactionType transaction = TransactionType.NoTransaction);

        List<TypeInfoEntity> GetTypeInfos(ConnectionModel connection=null);
    }
}
